// client.cpp
#define _WIN32_DCOM
#include <iostream.h>
#include <stdio.h>
#include "Component\component.h"
#include "ChannelHook\channelhook.h"

void main()
{
	cout << "Client: Calling CoInitialize()" << endl;
	CoInitialize(NULL);

	// Load the channel hook
	void* silly;
	CoCreateInstance(CLSID_ClientChannelHook, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, &silly);

	/*
	To connect to the Component on the local machine use:
	   COSERVERINFO ServerInfo = { 0, 0, 0, 0 };

	To connect to the Component on a remote machine use:
	   COSERVERINFO ServerInfo = { 0, L"YourServerName", 0, 0 };
	*/
	COSERVERINFO ServerInfo = { 0, 0, 0, 0 };

	cout << "Client: Calling CoCreateInstance() " << endl;
	MULTI_QI qi = { &IID_IUnknown, NULL, 0 };
	HRESULT hr = CoCreateInstanceEx(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, &ServerInfo, 1, &qi);
	if(FAILED(hr))
	{
		printf("Client: hr = %0x\n", hr);
		exit(0);
	}

	ISum* pSum;
	qi.pItf->QueryInterface(IID_ISum, (void**)&pSum);

	int sum;
	hr = pSum->Sum(4, 9, &sum);
	cout << "Client: Calling Sum() return value is " << sum << endl;
	printf("HRESULT is %x\n", hr);

	cout << "Client: Calling Release() for pSum" << endl;
	hr = pSum->Release();

	cout << "Client: Calling CoUninitialize()" << endl;
	qi.pItf->Release();
	CoUninitialize();
}